

<template>
  <div>
    <el-button class="butB_Sel" @click="printBtn()">打印</el-button>
    <el-button class="butB_Sel" @click="printBtn2()">打印2</el-button>
    <div class="app-container" id="printcons">
      <div
        class=""
        style="
          width: 1100px;
          margin: auto;
          padding: 0px 50px;
          padding-top: 100px;
          font-size: 14px;
        "
        v-for="(item2, it) in drug2"
        :key="it"
      >
        <div>
          <h2 style="text-align: center; margin: 0 5px">
             长期医嘱单          </h2>

          <p style="width: 16%; float: left">
            病区:
            <span style="">{{ tabeldata.room }}</span>
          </p>
          <p style="width: 16%; float: left">
            床号:
            <span style="">{{ tabeldata.name }}</span>
          </p>
          <p style="width: 16%; float: left">
            姓名:
            <span style="">{{ tabeldata.member.name }}</span>
          </p>
          <p style="width: 16%; float: left">
            性别:
            <span style="">{{
              tabeldata.member.gender == 1
                ? "男"
                : tabeldata.member.gender == 2
                ? "女"
                : "未知"
            }}</span>
          </p>
          <p style="width: 16%; float: left">
            年龄:
            <span style="">{{ tabeldata.member.age }}岁</span>
          </p>
          <p style="width: 16%; float: left">
            住院号:
            <span style="">{{ tabeldata.ipt_no }}</span>
          </p>
          <table
            border="1"
            width="1000"
            align="center"
            cellspacing="0"
            cellpadding="0"
          >
            <tr style="height: 30px; text-align: center">
              <td colspan="2">开始</td>

              <td rowspan="2" style="width: 300px; height: 30px">
                长期医嘱
              </td>
              <td colspan="2">签名</td>

              <td colspan="2">停止</td>

              <td colspan="2">签名</td>
            </tr>
            <tr style="height: 30px">
              <td style="">日期</td>
              <td>时间</td>

              <td>医生</td>

              <td>护士</td>

              <td style="">日期</td>
              <td>时间</td>
              <td>医生</td>

              <td>护士</td>
            </tr>
            <tr
              v-for="(item, index) in item2"
              :key="index"
              style="height: 30px"
            >
              <td>{{ item.start_time.split(" ")[0] }}</td>
              <td>{{ item.start_time.split(" ")[1] }}</td>

              <td
                :style="
                  item.advice_type == '0'
                    ? 'text-align: center;position: relative;'
                    : 'text-align: left;position: relative;'
                "
              >
                {{ item.business_name }}
                <div
                  :style="
                    item.id2 == '1'
                      ? 'position: absolute;right:10px;top:0px;height:100%;width:2px;background: #000000'
                      : ''
                  "
                ></div>
              </td>
              <td>{{ item.advice_doctor_name }}</td>

              <td>{{ item.execution_user_name }}</td>
              <td>
                {{
                  item.end_time.split(" ")[0] == "0000-00-00"
                    ? ""
                    : item.end_time.split(" ")[0]
                }}
              </td>
              <td>
                {{
                  item.end_time.split(" ")[1] == "00:00:00"
                    ? ""
                    : item.end_time.split(" ")[1]
                }}
              </td>

              <td>{{ item.stop_doctor_name }}</td>
              <td>{{ item.stop_nurse_name }}</td>
            </tr>
          </table>
        </div>
        <p>第{{ it + 1 }}页 /共 {{drug2.length}} 页 审核医生：</p>
       
      </div>
    </div>
  </div>
</template>
<script>
import { getdictIndex } from "@/api/register";
export default {
  props: ["yizhudata", "type"],
  data() {
    return {
      tabeldata: {
        name: "",
        room: "",
      },
      sourcelist: [],
      arrdata: [],
      drug2: [],
      dayin: false,
    };
  },

  mounted() {
    this.drug2=[]
      this.yizhudata =JSON.parse(this.$route.query.yizhudata)
    this.tabeldata = this.yizhudata.info;
    console.log(this.yizhudata);
    this.tabeldata.room_nameA = this.tabeldata.room_name.split("/");
    this.tabeldata.room = this.tabeldata.room_nameA[1];
    this.tabeldata.name = this.tabeldata.room_nameA[3];
    this.tabeldata2 = this.yizhudata.advice;
    // 		if (this.tabeldata2.length<40) {
    // 	for (let i = 0; i < 40-this.tabeldata2.length; i++) {

    // 		this.tabeldata2.push({
    // 			advice_doctor: '',
    // 			advice_doctor_name: "",
    // 			business_name: "",
    // 			end_time: " ",
    // 			start_time: " ",
    // 			is_group:0,
    // 			stop_doctor_name: '',
    // 			stop_nurse_name: '',
    // 			specification:'',
    // 			advice_type:'0',
    // 			show_usage:'',
    // 			used_frqu:{
    // 				name:''
    // 			}
    // 		})

    // 	}
    // }
    this.arrdata = this.tabeldata2;
    for (let i = 0; i < this.tabeldata2.length; i++) {
      if (this.tabeldata2[i].advice_type == 2) {
        this.tabeldata2[i].id2 = "";
        var arr = {
          advice_doctor: "",
          advice_doctor_name: "··",
          business_name: this.tabeldata2[i].show_usage,
          end_time: "··",
          start_time: "··",
          advice_type: "0",
          is_group: this.tabeldata2[i].is_group,
          stop_doctor_name: "··",
          stop_nurse_name: "··",
          specification: "··",
          usage: "··",
          used_frqu: {
            name: "",
          },
        };
        this.arrdata.splice(i + 1, 0, arr);
        // tabeldata2
        // console.log(i)
      }
    }
    this.tabeldata2 = this.arrdata;
    if (this.tabeldata2.length > 40) {
      var arr = this.tabeldata2;
      for (let i = 0; i < Math.ceil(arr.length / 40); i++) {
        this.drug2.push(arr.slice(i*40, 40*(i+1)));
      }
    } else {
      this.drug2.push(this.tabeldata2);
      console.log(this.drug2);
    }
    var aty = this.drug2[this.drug2.length - 1];
    var num = 40 - parseInt(aty.length);
    console.log(num);
    if (num < 40) {
      for (let i = 0; i < num; i++) {
      
        this.drug2[this.drug2.length - 1].push({
          advice_doctor: "",
          advice_doctor_name: "",
          business_name: "",
          end_time: " ",
          start_time: " ",
          is_group: 0,
          stop_doctor_name: "",
          stop_nurse_name: "",
          specification: "",
          advice_type: "0",
          show_usage: "",
          used_frqu: {
            name: "",
          },
        });
      }
    }
    this.tianjiaids2();
  },
  // watch: {
  //   yizhudata(n) {
	// 	console.log(n)
	// 	this.drug2=[]
	// 	this.tabeldata2=[]
  //     this.tabeldata = n.info;
  //     this.tabeldata.room_nameA = this.tabeldata.room_name.split("/");
  //     this.tabeldata.room = this.tabeldata.room_nameA[1];
  //     this.tabeldata.name = this.tabeldata.room_nameA[3];
  //     this.tabeldata2 = n.advice;
  //     this.arrdata = this.tabeldata2;
  //     for (let i = 0; i < this.tabeldata2.length; i++) {
  //       if (this.tabeldata2[i].advice_type == 2) {
  //         this.tabeldata2[i].id2 = "";
  //         var arr = {
  //           advice_doctor: "",
  //           advice_doctor_name: "··",
  //           business_name: this.tabeldata2[i].show_usage,
  //           end_time: "··",
  //           start_time: "··",
  //           advice_type: "0",
  //           is_group: this.tabeldata2[i].is_group,
  //           stop_doctor_name: "··",
  //           stop_nurse_name: "··",
  //           specification: "··",
  //           usage: "··",
  //           used_frqu: {
  //             name: "",
  //           },
  //         };
  //         this.arrdata.splice(i + 1, 0, arr);

  //       }
  //     }
  //     this.tabeldata2 = this.arrdata;
  //     if (this.tabeldata2.length > 40) {
  //       var arr = this.tabeldata2;
  //       for (let i = 0; i < Math.ceil(arr.length / 40); i++) {
  //         this.drug2.push(arr.slice(i*40, 40*(i+1)));
  //       }
  //       console.log(this.drug2);
  //     } else {
  //       this.drug2.push(this.tabeldata2);
  //     }
  //     var aty = this.drug2[this.drug2.length - 1];
  //     var num = 40 - parseInt(aty.length);

  //     if (num < 40) {
  //       for (let i = 0; i < num; i++) {
  //         this.drug2[this.drug2.length - 1].push({
  //           advice_doctor: "",
  //           advice_doctor_name: "",
  //           business_name: "",
  //           end_time: " ",
  //           start_time: " ",
  //           is_group: 0,
  //           stop_doctor_name: "",
  //           stop_nurse_name: "",
  //           specification: "",
  //           advice_type: "0",
  //           show_usage: "",
  //           used_frqu: {
  //             name: "",
  //           },
  //         });
  //       }
  //     }
  //     this.tianjiaids2();
  //   },
  // },
  methods: {
    tianjiaids2() {
      for (let j = 0; j < this.tabeldata2.length; j++) {
        if (
          this.tabeldata2[j].is_group != null &&
          this.tabeldata2[j].is_group != 0
        ) {
          var arr = [];
          for (let i = 0; i < this.tabeldata2.length; i++) {
            if (
              this.tabeldata2[i].is_group == this.tabeldata2[j].is_group &&
              this.tabeldata2[j].advice_type
            ) {
              arr.push(i);
            }
          }
          for (let i = 0; i < arr.length; i++) {
            this.tabeldata2[arr[i]].id2 = "1";
          }
        }
      }
    },
    getindex() {
      getdictIndex({ group_id: "40" }).then((res) => {
        let data = res.data;
        data.forEach((item, key) => {
          if (item.id == 40) {
            this.sourcelist = item.items;
          }
        });
      });
    },
    getpint() {
      this["_API"].getPrintReport({ id: this.id }).then((res) => {
        if (res.code == 200) {
          this.tabeldata = res.data;
          this.tabeldata.source = this.mapxing(this.tabeldata.source);
        }
      });
    },

    mapxing(num) {
      var art = "";
      this.sourcelist.map(function (value, i, array) {
        if (value.id == num) {
          art = value.name;
        }
      });
      console.log(art);
      return art;
    },
    printBtn(e) {
      this.dayin = true;
      setTimeout(() => {
        this.dayinfun();
      }, 200);
    },
     printBtn2(e) {
      this.CreateOneFormPage();
    },
      CreateOneFormPage() {
      this.LODOP = getLodop();
      // this.LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_表单一");
      // this.LODOP.SET_PRINT_PAGESIZE(3,'21mm',0);
      //  this.LODOP.DO_ACTION("PREVIEW_ZOOM_WIDTH")
      // this.LODOP.SET_PRINT_STYLE("FontSize", 18);
      // this.LODOP.SET_PRINT_STYLE("Bold", 1);
      LODOP.SET_PREVIEW_WINDOW(1,2,0,0,0,"预览查看.开始打印");

      this.LODOP.ADD_PRINT_TEXT(50,231,260,39,"打印页面部分内容");
      this.LODOP.ADD_PRINT_HTM(
        50,
        30,
        "100%",
        "BottomMargin:9mm",
        document.getElementById("printcons").innerHTML
      );
      this.LODOP.PREVIEW();
    },
    dayinfun() {
      this.remove_ie_header_and_footer();
      let subOutputRankPrint = document.getElementById("printcons");
      console.log(subOutputRankPrint.innerHTML);
      let newContent = subOutputRankPrint.innerHTML;
      let oldContent = document.body.innerHTML;
      document.body.innerHTML = newContent;
      window.print();
        window.open('','_self').close(),
      this.$emit("reload");
      document.body.innerHTML = oldContent;
      return false;
    },
    //去掉页眉和页脚
    remove_ie_header_and_footer() {
      var hkey_path;
      hkey_path =
        "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
      } catch (e) {}
    },
  },
};
</script>
<style media="print">
@page {
  size: auto; /* auto is the initial value */
  margin: 0mm; /* this affects the margin in the printer settings */
}
@media print {
}
body {
  -webkit-print-color-adjust: exact;
}
#printcons >>> td {
  width: 150px;
  height: 30px !important;

  /* border: 0.5px solid #000000; */
  padding: 0rem;
  margin: 0rem;
  text-align: center;
}
</style>
<style lang='scss' scoped>
#printcons >>> tr {
  height: 30px !important;
  padding: 20px 10px;
  margin: 0rem;
  text-align: center !important
}
#printcons >>> td {
  width: 150px;
  height: 30px !important;
  height: 100%;
  /* border: 0.5px solid #000000; */
  padding: 0rem;
  margin: 0rem;
  text-align: center;
}
</style>